// 导入axios
import axios from 'axios'
// 导入进度条插件
import NProgress from 'nprogress'
// 导入进度条样式
import 'nprogress/nprogress.css'
// 配置请求的基准URL地址
// const BASEURL = 'https://www.mifengzhujia.cn/api/mfzj/public/index.php'
const staticURL = 'https://www.mifengzhujia.cn/api/mfzj/public'
const BASEURL = '/api'
// const staticURL = 'http://192.168.3.24:8080/mfzj/public'
axios.defaults.headers.post['Content-Type'] = 'application/json'
axios.defaults.baseURL = BASEURL
// axios设置请求拦截器
axios.interceptors.request.use(
  config => {
    // 发请求开启进度条
    NProgress.start()
    //  设置请求头
    // config.headers.token = window.sessionStorage.getItem('token')

    return config
  },
  err => {
    console.log(err)
  }
)
// 响应拦截器
// axios设置响应拦截器
axios.interceptors.response.use(config => {
  // 关闭进度条
  NProgress.done()
  return config
}, err => {
  console.log(err)
})
// 请求封装
const httpGet = (url, data = {}) => {
  return axios.get(url, data)
}
const httpPost = (url, data = {}) => {
  return axios.post(url, data)
}

export default {
  httpGet,
  httpPost,
  BASEURL,
  staticURL
}
